#include <stdio.h>
#include "../include/queue.h"

typedef struct node_s {
	int a;
	queue_t queue;
} node_t;

#define N 5

void check_queue() {
	queue_t head;
	queue_t * p;
	node_t nodes[N];
	node_t * pnode;
	int i = 0;
	
	init_head(queue_t, &head);
	for (i = 0; i < N; ++i) {
		nodes[i].a = i+1;
	}
	
	for (i = 0; i < N; ++i) {
		if (queue_is_exist(&head, &nodes[i].queue)) {
			printf("wrong: queue_is_exist\n");
			return;
		}
		queue_push(&head, &nodes[i].queue);
		queue_push(&head, &nodes[i].queue);
		if (!queue_is_exist(&head, &nodes[i].queue)) {
			printf("wrong: queue_is_exist\n");
		}
	}
	printf("right:queue_is_exist\n");

	for(i = 1; (p = queue_pop(&head)) != NULL; ++i ) {
		pnode = entry(p, node_t, queue);
		if (i != pnode->a) {
			printf("wrong: queue\n");	
			return ;
		}	
		printf("%d ", pnode->a);
	}	
	printf("right: queue\n");
	
	queue_empty(&head);
	if (queue_is_empty(&head)) {
		printf("right: queue_empty\n");
		return ;
	}
	else {
		printf("wrong: queue_empty\n");
	}

}
int main(int argc, char * argv[]) {
	check_queue();
	return 0;	
}
